<admintpl file="header" />
<style>
    .ui-dialog {
        z-index: 1000px;
    }
</style>
</head>
<body>
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li class="active"><a href="{:U('Materials/index')}">物料管理</a></li>
            <li><a href="{:U('Materials/add')}">添加物料</a></li>
            <li><a href="{:U('Materials/real')}" >卡券列表</a></li>
        </ul>
        <form class="well form-search" method="post" action="{:U('Materials/index')}">
            分类：
            <select class="select_2" name="card_type">
                <option value='0'>全部</option>
                <foreach name="cardTypeList" item="vo">
                    <option <if condition="(I('param.card_type') eq $vo['id'])" >selected</if> value="{$vo.id}">{$vo.name}</option>
                </foreach>
            </select> &nbsp;&nbsp;
            时间：
            <input type="text" name="start_time" class="js-date" value="{:I('param.start_time')}" style="width: 80px;" autocomplete="off">-
            <input type="text" name="end_time" class="js-date"  value="{:I('param.end_time')}" style="width: 80px;" autocomplete="off"> &nbsp; &nbsp;
            关键字：
            <input type="text" name="keyword" style="width: 200px;" value="{:I('param.keyword')}" placeholder="请输入关键字...">
            <input type="submit" class="btn btn-primary" value="搜索" />
            <if condition="$count" >共查询到 {$count} 条数据</if>
        </form>
            <table class="table table-hover table-bordered">
                <thead>
                    <tr>
                        <th>物料名称</th>
                        <th>类型</th>
                        <th>已领/<br>总量</th>
                        <th>当天中奖/<br>当天总量</th>
                        <th width="120">开始 - 结束</th>
                        <th>状态</th>
                        <th>审核</th>
                        <th>属主</th>
                    	<th>最后<br>操作人</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <foreach name="cards" item="vo">
                    <tr>
                        <td><if condition="$vo['card_type'] eq 2 || $vo['card_type'] eq 5">
                        	<a href="{:U('Materials/real',array('id'=>$vo['id']))}" title="查看实物"<if condition="$vo['end_at'] lt date('Y-m-d H:i:s')">style="color: #FF0000;"</if>>{$vo.card_name}</a>
                        	<else />{$vo.card_name}
                            </if>
                        </td>
                        <td>{$cardTypeList[$vo['card_type']-1]['name']}</td>
                        <td>{$vo.card_get_count}/{$vo.card_count}</td>
                        <td>{$vo['card_get_count_day'] ? $vo['card_get_count_day'] : 0 } / {$vo['card_count_day'] ? $vo['card_count_day'] : '不限制' }</td>
                        <td>{$vo.start_at} <br> {$vo.end_at}</td>
                        <td>
							<foreach name="card_status" item="status">
                                <if condition="$status['id'] eq $vo['card_status']">
                                    {$status['name']}
                                </if>
                            </foreach>
                        </td>
                        <td>{$vo.reason}</td>
                        <td><foreach name="users" item="user"><if condition="$vo['create_by'] eq $user['id']">{$user.user_login}</if></foreach></td>
                        <td><foreach name="users" item="user"><if condition="$vo['userid'] eq $user['id']">{$user.user_login}</if></foreach></td>
                        <td>
                            <if condition="$vo['card_status'] eq 0">
                                <a class="pub-dialog" data-toggle="modal" data-target="#pubModal" data-id="{$vo['id']}" style="color: #FF0000;"><b>发布</b></a> |
                            </if>
                            <if condition="$vo['card_status'] eq 1">
                                <a href="{:U('Materials/down',array('id'=>$vo['id']))}" class="js-ajax-dialog-btn" data-msg="您确定要暂停发放吗？" style="color: #FF0000;"><b>暂停</b></a> |
                            </if>
							<if condition="$vo['card_status'] eq 4">
								<a href="{:U('Materials/up',array('id'=>$vo['id']))}" class="js-ajax-dialog-btn" data-msg="您确定要开重新开启吗？">重新开启</a> |
							</if>
                            <if condition="$admin['role_id'] lt 20 ">
                                <if condition="$vo['card_status'] eq 2">
                                    <a class="pending" data-remote="{$web_domain}/index.php?g=Operations&m=Materials&a=preview&id={$vo['id']}" data-toggle="modal" data-target="#myModal" data-id="{$vo['id']}"
                                       style="color: #FF0000; margin-top: 1%;"><b>审核</b></a> |
                                </if>
                                <if condition="$vo['card_status'] eq 1">
                                    <a href="{:U('Materials/disable',array('id'=>$vo['id']))}" class="js-ajax-dialog-btn" data-msg="您确定要开强制停止吗？">强制停止</a> |
                                </if>
                                <if condition="$vo['card_status'] eq 11">
                                    <a href="{:U('Materials/valid',array('id'=>$vo['id']))}" class="js-ajax-dialog-btn" data-msg="您确定要开强制停止吗？">强制停止恢复</a> |
                                </if>
<!--                                <if condition="$vo['card_status'] eq 3">
                                    <a href="{:U('Materials/pub',array('id'=>$vo['id']))}" class="js-ajax-dialog-btn" data-msg="您确定要发布吗吗？通过审核就可以使用" style="color: #FF0000;"><b>发布</b></a> |
                                </if>-->
                            </if>
                            <a href="{:U('Materials/edit', array('id'=>$vo['id']))}">{:L('EDIT')}</a> |
                            <a href="{:U('Materials/delete', array('id'=>$vo['id']))}" class="js-ajax-delete">{:L('DELETE')}</a>
                        </td>
                    </tr>
                </foreach>
                <thead>
                    <tr>
                        <th>物料名称</th>
                        <th>类型</th>
                        <th>已领/<br>总量</th>
                        <th>当天中奖/<br>当天总量</th>
                        <th>开始 - 结束</th>
                        <th>状态</th>
                        <th>审核</th>
                        <th>属主</th>
                        <th>最后<br>操作人</th>
                        <th>操作</th>
                    </tr>
                </thead>
            </table>
            <div class="pagination">{$Page}</div>
    </div>
    <div class="modal hide fade" id="pubModal">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3>发布物料</h3>
        </div>
        <div class="modal-body">
            <form class="form-horizontal" id="eventList">
                <input id="pub_card_id" name="id" type="hidden" >
                <div class="control-group">
                    <foreach name="openEvents" item="vo">
                        <label class="radio">
                            <input name="events[]" type="radio" value="{$vo.id}">
                            <span>{$vo.event_name}</span>
                        </label>
                    </foreach>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
            <button class="btn btn-success" id="pub">确认发布</button>
        </div>
    </div>
    <script src="__PUBLIC__/js/common.js"></script>
    <div class="modal hide fade" id="myModal">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3>物料审核</h3>
        </div>
        <div class="modal-body">
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
            <button class="btn btn-danger" id="not_pass">审核不通过</button>
            <button class="btn btn-success" id="pass">审核通过</button>
        </div>
    </div>
    <script src="__PUBLIC__/js/common.js"></script>
    <script>
        var tmp_id = '';
        $('.pending').click(function(){
            tmp_id = $(this).attr("data-id");
        });
        $('#pass').click(function(){
            var jsonData = $("#prev-from").serializeArray();
            $.post("{:U('Operations/Materials/pass')}", jsonData, function( data ) {
                if (data.status == 0) {
                    show_msg( data.info);
                } else {
                    if (data.status == 0) {
                        show_msg( data.info)
                    } else {
                        show_msg('操作成功');
                    }
                }
            });
        });
        $('#not_pass').click(function(){
            var reason = $("textarea[name='reason']").val();
            if (!reason) {
                show_msg('审核原因不能为空');
                return;
            }
            var jsonData = $("#prev-from").serializeArray();
            $.post("{:U('Operations/Materials/not_pass')}", jsonData, function( data ) {
                if (data.status == 0) {
                    show_msg(data.info);
                } else {
                    show_msg('操作成功');
                }
            });
        });
        $('#pub').click(function(){
            var jsonData = $("#eventList").serializeArray();
            $.post("{:U('Operations/Materials/pub')}", jsonData, function( data ) {
                if (data.status == 0) {
                    show_msg( data.info);
                } else {
                    if (data.status == 0) {
                        show_msg(data.info)
                    } else {
                        show_msg('操作成功');
                    }
                }
            });
        });
        $('#myModal').css({
            'width': 'auto',
            'margin-left': '-50%',
            'margin-top': '-5%',
        });
        $('.pub-dialog').on('click', function () {
            $("#pub_card_id").val($(this).attr('data-id'));
        })
        function  close_modal() {
            $('#myModal').modal('hide');
            location.reload();
        }
        function  show_modal() {
            $('#myModal').modal('show');
        }
        function show_msg(msg) {
             cur_dialog =  art.dialog({
                 content: msg,
                 quickClose: true
            });
            cur_dialog.show();
            setTimeout('close_modal();', 1500);
            setTimeout('cur_dialog.close()', 1500);
        }

    </script>
</body>
</html>